#include "Earth.h"

bool Earth::initPlugin()
{
	//Node* earthNode = osgDB::readNodeFile("./resources/Earth/globe.ive");
	Node* earthNode = osgDB::readNodeFile("../../Earth_resource/globe.ive");
	if (!earthNode)
	{
		return false;
	}

	float radius = earthNode->getBound().radius();
	Vec3 center = earthNode->getBound().center();

	float scale = EARTH_R / radius * 1.72;

	MatrixTransform* trans = new MatrixTransform;
	Matrixd mat1, mat2, mat3;
	mat1.makeTranslate(-center);
	mat2.makeScale(scale, scale, scale);
	mat3.makeRotate(-PI_2, Vec3(1, 0, 0),
					-PI_2, Vec3(0, 1, 0),
					 0   , Vec3(0, 0, 1));
	trans->setMatrix(mat1 * mat2 * mat3);
	trans->addChild(earthNode);

	getParentViewer()->getLayerManager()->addToNewLayer(trans, "Earth");

	return true;
}